package com.antd.auth.service;

import org.springframework.security.oauth2.common.exceptions.InvalidClientException;
import org.springframework.security.oauth2.provider.ClientDetails;
import org.springframework.security.oauth2.provider.client.JdbcClientDetailsService;

import javax.sql.DataSource;
import java.util.HashMap;
import java.util.Map;

/**
 * TODO
 *
 * @author 子丶沫
 * @version 1.0
 * @date 2020/11/20 10:37
 */
public class AntdClientDetailService extends JdbcClientDetailsService {
    private static final Map<String, ClientDetails> CLIENTS = new HashMap<>();
    public AntdClientDetailService(DataSource dataSource) {
        super(dataSource);
    }


    @Override
    public ClientDetails loadClientByClientId(String clientId) throws InvalidClientException {
        ClientDetails clientDetails = CLIENTS.get(clientId);
        if (clientDetails != null) {
            return clientDetails;
        }
        ClientDetails clientDetails1 = super.loadClientByClientId(clientId);
        CLIENTS.put(clientId, clientDetails1);
        return clientDetails1;
    }
}
